package edu.unf.cen6940.web;

import edu.unf.cen6940.dao.ThesisDAO;
import edu.unf.cen6940.dao.ThesistoolDAO;

import edu.unf.cen6940.domain.Thesis;
import edu.unf.cen6940.domain.Thesistool;

import edu.unf.cen6940.service.ThesistoolService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.servlet.ModelAndView;

/**
 * Spring MVC controller that handles CRUD requests for Thesistool entities
 * 
 */

@Controller("ThesistoolController")
public class ThesistoolController {

	/**
	 * DAO injected by Spring that manages Thesis entities
	 * 
	 */
	@Autowired
	private ThesisDAO thesisDAO;

	/**
	 * DAO injected by Spring that manages Thesistool entities
	 * 
	 */
	@Autowired
	private ThesistoolDAO thesistoolDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for Thesistool entities
	 * 
	 */
	@Autowired
	private ThesistoolService thesistoolService;

	/**
	 * Show all Thesistool entities
	 * 
	 */
	@RequestMapping("/indexThesistool")
	public String listThesistools(Model model) {
		model.addAttribute("thesistools", thesistoolService.loadThesistools());
		return "thesistool/listThesistools";
	}

	/**
	 * Edit an existing Thesistool entity
	 * 
	 */
	@RequestMapping("/editThesistool")
	public ModelAndView editThesistool(@RequestParam Integer thesistoolIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("thesistool", thesistoolDAO.findThesistoolByPrimaryKey(thesistoolIdKey));
		mav.setViewName("thesistool/editThesistool");

		return mav;
	}

	/**
	 * Delete an existing Thesistool entity
	 * 
	 */
	@RequestMapping("/deleteThesistool")
	public String deleteThesistool(@RequestParam Integer thesistoolIdKey) {
		Thesistool thesistool = thesistoolDAO.findThesistoolByPrimaryKey(thesistoolIdKey);
		thesistoolService.deleteThesistool(thesistool);
		return "forward:/indexThesistool";
	}

	/**
	 * Create a new Thesistool entity
	 * 
	 */
	@RequestMapping("/newThesistool")
	public ModelAndView newThesistool() {
		ModelAndView mav = new ModelAndView();

		mav.addObject("thesistool", new Thesistool());
		mav.addObject("newFlag", true);
		mav.setViewName("thesistool/editThesistool");

		return mav;
	}

	/**
	 * Save an existing Thesis entity
	 * 
	 */
	@RequestMapping("/saveThesistoolThesises")
	public ModelAndView saveThesistoolThesises(@RequestParam Integer thesistool_thesisToolId, @ModelAttribute Thesis thesises) {
		Thesistool parent_thesistool = thesistoolService.saveThesistoolThesises(thesistool_thesisToolId, thesises);

		ModelAndView mav = new ModelAndView();
		mav.addObject("thesistool_thesisToolId", thesistool_thesisToolId);
		mav.addObject("thesistool", parent_thesistool);
		mav.setViewName("thesistool/viewThesistool.jsp");

		return mav;
	}

	/**
	 * Delete an existing Thesis entity
	 * 
	 */
	@RequestMapping("/deleteThesistoolThesises")
	public ModelAndView deleteThesistoolThesises(@RequestParam Integer thesistool_thesisToolId, @RequestParam Integer related_thesises_thesisId) {
		ModelAndView mav = new ModelAndView();

		Thesistool thesistool = thesistoolService.deleteThesistoolThesises(thesistool_thesisToolId, related_thesises_thesisId);

		mav.addObject("thesistool_thesisToolId", thesistool_thesisToolId);
		mav.addObject("thesistool", thesistool);
		mav.setViewName("thesistool/viewThesistool.jsp");

		return mav;
	}

	/**
	 * Save an existing Thesistool entity
	 * 
	 */
	@RequestMapping("/saveThesistool")
	public String saveThesistool(@ModelAttribute Thesistool thesistool) {
		thesistoolService.saveThesistool(thesistool);
		return "forward:/indexThesistool";
	}

	/**
	 * Entry point to show all Thesistool entities
	 * 
	 */
	public String indexThesistool() {
		return "redirect:/indexThesistool";
	}

	/**
	 * Select the Thesistool entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@RequestMapping("/confirmDeleteThesistool")
	public ModelAndView confirmDeleteThesistool(@RequestParam Integer thesistoolIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("thesistool", thesistoolDAO.findThesistoolByPrimaryKey(thesistoolIdKey));
		mav.setViewName("thesistool/deleteThesistool");

		return mav;
	}

	/**
	 * Edit an existing Thesis entity
	 * 
	 */
	@RequestMapping("/editThesistoolThesises")
	public ModelAndView editThesistoolThesises(@RequestParam Integer thesistool_thesisToolId, @RequestParam Integer thesises_thesisId) {
		Thesis thesis = thesisDAO.findThesisByPrimaryKey(thesises_thesisId, -1, -1);

		ModelAndView mav = new ModelAndView();
		mav.addObject("thesistool_thesisToolId", thesistool_thesisToolId);
		mav.addObject("thesis", thesis);
		mav.setViewName("thesistool/thesises/editThesises.jsp");

		return mav;
	}

	/**
	 * Show all Thesis entities by Thesistool
	 * 
	 */
	@RequestMapping("/listThesistoolThesises")
	public ModelAndView listThesistoolThesises(@RequestParam Integer thesisToolIdKey) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("thesistool", thesistoolDAO.findThesistoolByPrimaryKey(thesisToolIdKey));
		mav.setViewName("thesistool/thesises/listThesises.jsp");

		return mav;
	}

	/**
	 * Select an existing Thesistool entity
	 * 
	 */
	@RequestMapping("/selectThesistool")
	public String selectThesistool(@RequestParam Integer thesistoolIdKey, Model model) {

		model.addAttribute("thesistool", thesistoolDAO.findThesistoolByPrimaryKey(thesistoolIdKey));
		return "thesistool/viewThesistool";
	}

	/**
	 * View an existing Thesis entity
	 * 
	 */
	@RequestMapping("/selectThesistoolThesises")
	public ModelAndView selectThesistoolThesises(@RequestParam Integer thesistool_thesisToolId, @RequestParam Integer thesises_thesisId) {
		Thesis thesis = thesisDAO.findThesisByPrimaryKey(thesises_thesisId, -1, -1);

		ModelAndView mav = new ModelAndView();
		mav.addObject("thesistool_thesisToolId", thesistool_thesisToolId);
		mav.addObject("thesis", thesis);
		mav.setViewName("thesistool/thesises/viewThesises.jsp");

		return mav;
	}

	/**
	 * Register custom, context-specific property editors
	 * 
	 */
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	 */
	@RequestMapping("/thesistoolController/binary.action")
	public ModelAndView streamBinary(@ModelAttribute HttpServletRequest request, @ModelAttribute HttpServletResponse response) {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("streamedBinaryContentView");
		return mav;

	}

	/**
	 * Create a new Thesis entity
	 * 
	 */
	@RequestMapping("/newThesistoolThesises")
	public ModelAndView newThesistoolThesises(@RequestParam Integer thesistool_thesisToolId) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("thesistool_thesisToolId", thesistool_thesisToolId);
		mav.addObject("thesis", new Thesis());
		mav.addObject("newFlag", true);
		mav.setViewName("thesistool/thesises/editThesises.jsp");

		return mav;
	}

	/**
	 * Select the child Thesis entity for display allowing the user to confirm that they would like to delete the entity
	 * 
	 */
	@RequestMapping("/confirmDeleteThesistoolThesises")
	public ModelAndView confirmDeleteThesistoolThesises(@RequestParam Integer thesistool_thesisToolId, @RequestParam Integer related_thesises_thesisId) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("thesis", thesisDAO.findThesisByPrimaryKey(related_thesises_thesisId));
		mav.addObject("thesistool_thesisToolId", thesistool_thesisToolId);
		mav.setViewName("thesistool/thesises/deleteThesises.jsp");

		return mav;
	}
}